<template>
  <div class="container">
    <scroll-view :scroll-y="true" :style="{'height': '100%'}" @scroll="scroll">
      <div class="card_list" v-for="item in list" :key="item">
        <div class="card_left">
          <img :src="imgUrl+item.image" class="img">
        </div>
        <div class="card_right">
          <p class="card_top">
            <!-- <img src="https://h5.ameimeika.com/mp_images/mp_2.1/other/icon_order_film.png"
            class="img">-->
            <span class="title">票券编码</span>
            <span class="intro">{{item.name}}</span>
          </p>
          <p class="card_middle">
            <span class="card_num">{{item.ticket_code}}</span>
            <span
              v-if="item.end_status==1"
              @click="copy_num(item.ticket_code,item.path)"
              class="copy"
              :class="{'redeem_now':item.end_status==1}"
            >立即兑换</span>
            <span v-if="item.end_status==2" class="copy" :class="{'redeem':item.end_status==2}">已兑换</span>
          </p>
          <p class="card_down">
            <span class="card_dname">兑换截止日期：</span>
            <span class="card_time">{{item.time}}</span>
          </p>
        </div>
        <img
          v-if="item.end_status == 3"
          class="card_status"
          src="https://h5.ameimeika.com/mp_images/mp_2.1/other/icon_order_expired.png"
        >
      </div>
    </scroll-view>
  </div>
</template>

<script>
import common from "@/assets/js/mmk_common.js";
import base64 from "@/assets/js/base64.js";
export default {
  data() {
    return {
      list: [],
      imgUrl: common.image_response
    };
  },
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: "票券详情"
    });
    this.ticket_id = options.ticket_id;
    this.getlist();
  },
  methods: {
    getlist() {
      let that = this;
      wx.showLoading({
        title: "加载中", //提示的内容,
        mask: true //显示透明蒙层，防止触摸穿透,
      });
      common.fly_post(
        "api/v4_2/order/goods_code",
        {
          id: that.ticket_id
        },
        response => {
          wx.hideLoading();
          let res = response.data;
          if (res.status_code == 0) {
            res.data.forEach(item => {
              item.time = new Date(item.end_time * 1000).Format("yyyy-MM-dd");
              // let ticket = (item.ticket_code).substr(9)
              // item.ticket = base64.decode(ticket)
            });
            this.list = res.data;
          }
        }
      );
    },
    copy_num: function(e, path) {
      wx.setClipboardData({
        data: e,
        success(res) {
          wx.showToast({
            title: "券码已复制",
            icon: "none",
            duration: 500,
            success: res => {
              setTimeout(res => {
                wx.navigateToMiniProgram(
                  {
                    appId: "wx836c6ce53dfc1176",
                    path: path,
                    envVersion: "release", //正式版
                    success(res) {
                      // 打开成功
                    }
                  },2500);
              });
            }
          });
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  background: #f3f4f6;
  .card_list {
    position: relative;
    background: url("https://h5.ameimeika.com/mp_images/mp_2.1/other/bg_order_ticket.png")
      no-repeat top left;
    background-size: 100%;
    width: 94%;
    margin: 0 auto;
    margin-top: 8px;
    height: 119px;
    text-align: center;
    overflow: hidden;
    .card_left {
      float: left;
      width: 32%;
      height: 110px;
      .img {
        display: block;
        margin: 0 auto;
        margin-top: 14%;
        margin-left: 20%;
        width: 81px;
        height: 81px;
      }
    }
    .card_right {
      text-align: left;
      padding-left: 12px;
      float: left;
      width: 63%;
      .card_top {
        margin-top: 8%;
        .img {
          width: 20px;
          height: 20px;
          vertical-align: middle;
        }
        .title {
          margin-left: 4px;
          display: inline-block;
          vertical-align: middle;
          font-size: 14px;
          color: #333333;
        }
        .intro {
          margin-left: 15px;
          display: inline-block;
          vertical-align: middle;
          font-size: 12px;
          color: #666666;
        }
      }
      .card_middle {
        margin: 11px 0;
        display: flex;
        justify-content: space-between;
        flex-wrap: nowrap;
        box-sizing: border-box;
        .card_num {
          font-size: 14px;
          color: #ff383e;
        }
        .copy {
          width: 60px;
          height: 17px;
          font-size: 12px;
          text-align: center;
          color: #ffffff;
          display: inline-block;
          padding: 0 5px;
          margin-right: 16px;
          margin-bottom: 4px;
        }
        .redeem_now {
          //立即兑换
          background: #fe6a9c;
        }
        .redeem {
          //已兑换
          background: #c5c5c5;
        }
      }
      .card_down {
        padding-left: 6px;
        font-size: 12px;
        color: #666666;
        opacity: 0.8;
      }
    }
    .card_status {
      width: 46px;
      height: 46px;
      position: absolute;
      right: 15px;
      top: 7px;
    }
  }
}
</style>

